Repository navigation
interscript-py: reverse-mode semantics — dep-closure replay, gsub scan, replacement collapse (WO20 shrink-to-zero) - #869
Merged
Conversation
ronaldtse
force-pushed
the
wo20-py-reverse-engine-fixes
branch
from
November 18, 2026 14:24
62d92a5 to
5ec609d
Compare
…acement collapse - WO20 reverse shrink-to-zero Six fixes closing the py side of the WO20 reverse-golden divergence families - the largest, 123 of the 125 excluded maps (rs PR wo20-reverse-shrink-to-zero is the reference side; with these the full 15,321-row reverse replay is 0-delta): - test_golden_reverse replays through the DEPENDENCY-CLOSURE-reversing flow (Runtime.reverse parity): the compiled IR carries dependency NAMES, so a reversed parent's run rules must execute REVERSED dependency maps - rs reverse_document recurses into them and ruby reverses Dependency#document. Replaying reverse_map against forward-dep resolvers made every run-carrying reversed doc execute the FORWARD dependency stage - the 91-map identity-output family (alalc-rus-2012 "Azov" -> "Azov" etc.). - parallel_megaregexp scans with ruby gsub semantics: python regex.sub continues at the SAME position after an empty match, so the next alternative ALSO fired there - double insertions where ruby inserts once (bgnpcgn-prs / bgnpcgn-pus). The scan now anchors each position (including end-of-string) and skips one character after a zero-width match, mirroring rs apply_parallel. - Repeat items collapse to their inner literal in replacement position (ruby Repeat#nth_string parity) - reversed rules whose `to` carries a maybe restored nothing (bgnpcgn-ara-1956 / hin-Deva / odni-ara / yaghoubi families). - `$N` group fallback inserts the EMPTY string, not the whole match - ruby gsub / rs decode_replacement semantics for unparticipated refs (the hin-Deva reversed `from "" to ref` rules). - Megaregexp drops rules whose from-pattern backreferences a group the pattern does not define (rs: a ref with an unparticipated group never matches; python's combined compile raised "invalid group reference", bgnpcgn-zho). - title_case upcases the first char of every LINE (ruby ^ is line-anchored), not just the string head (un-ell-Grek-Latn-1987-phonetic). test_executor's out-of-range capture-ref pin flips to the canonical empty-insertion semantics with the source-anchored justification (the old whole-match pin was the ts pre-fix behavior, diverging from rs and ruby).
ronaldtse
force-pushed
the
wo20-py-reverse-engine-fixes
branch
from
November 18, 2026 14:25
5ec609d to
6601920
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The py side of the WO20 reverse-golden shrink-to-zero (rs PR wo20-reverse-shrink-to-zero is the reference side; merge that first — it carries the grown golden this replay consumes). py was 123 of the 125 excluded maps; with this branch the full reverse replay is 0 deltas on 15,321 rows / 452 maps.
The headline fix is the dependency-closure replay: the compiled IR carries dependency names, so a reversed parent's run rules must execute reversed dependency maps (rs
reverse_documentrecursion / rubyDependency#reverseparity). The gate previously replayedreverse_mapagainst forward-dep resolvers, so every run-carrying reversed doc executed the forward dependency stage — the 91-map identity-output family (alalc-rus-2012's "Azov" → "Azov" etc.).Runtime.reversealready had the right flow; the gate now mirrors it.Plus five engine parity fixes: ruby-gsub scan semantics in
parallel_megaregexp(pythonregex.subcontinues at the same position after an empty match — bgnpcgn-prs/pus double-insert), repeat literal collapse,$Nempty-insertion fallback, undefined-ref megaregexp drops, and line-anchoredtitle_case.test_executor's out-of-range capture-ref pin flips to the canonical empty-insertion semantics with the source-anchored justification (the old whole-match pin was the pre-fix ts behavior, diverging from rs and ruby).Test plan
python3 -m pytest tests/: the only failure wastest_golden_captureagainst the STALE forward golden — pre-existing on main (pristine rs main fails its owngolden_captureidentically; the rs refresh commit reconciles it). Green after the refresh.test_golden_reverse.py+test_reverse.pygreen